DROP TABLE PAGO_SERVICIOS CASCADE CONSTRAINT;

CREATE TABLE PAGO_SERVICIOS(
  ID NUMBER NOT NULL PRIMARY KEY, /*CLAVE FORANEA CON MOVIMIENTOS*/
  ID_SERV VARCHAR(3) NOT NULL REFERENCES SERVICIOS(ID_SERV), /*CLAVE FORANEA CON SERVICIOS*/
  FECHA DATE NOT NULL,
  NRO_CUENTA NUMBER NOT NULL REFERENCES CUENTAS(NRO_CUENTA)); /*CLAVE FORANEA CON CUENTAS*/
  
  CREATE SEQUENCE S_PAGO_SERV;

--------------------------------------------------------
--  DDL for Trigger AI_PAGO_SERVICIOS
--------------------------------------------------------

  CREATE OR REPLACE TRIGGER "UTN_LABV"."AI_PAGO_SERVICIOS" 
   before insert on "UTN_LABV"."PAGO_SERVICIOS" 
   for each row 
begin  
   if inserting then 
      if :NEW."ID" is null then 
         select S_PAGO_SERV.nextval into :NEW."ID" from dual; 
      end if; 
   end if; 
end;

/
ALTER TRIGGER "UTN_LABV"."AI_PAGO_SERVICIOS" ENABLE;

